欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

std::remove

C++ VRCTOR中實際刪除元素使用的是容器vecrot中std::vector::erase()方。

C++ 中std::remove()并不刪除元素,因為容器的size()沒有變化,只是元素的替換。

1.std::vector::erase()

  函數(shù)原型:ITERATOR erase (iterator position);  //刪除指定元素

       iterator erase (iterator first, iterator last);  //刪除指定范圍內(nèi)的元素

  返回值:指向刪除元素(或范圍)的下一個元素。(An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.)

2.代碼實例

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 using namespace std;
 5 
 6 int out(vector<int> &iVec)
 7 {
 8     for(int i=0;i<iVec.size();i++)
 9         cout<<iVec[i]<<ends;
10     cout<<endl;
11     return 0;
12 }
13 
14 int main()
15 {
16     vector<int> iVec;
17     vector<int>::iterator it;
18     int i;
19     for( i=0;i<10;i++)
20         iVec.push_back(i);
21 
22     cout<<"The Num(old):";out(iVec);
23     for(it=iVec.begin();it!=iVec.end();)
24     {
25         if(*it % 3 ==0)
26             it=iVec.erase(it);    //刪除元素,返回值指向已刪除元素的下一個位置    
27         else
28             ++it;    //指向下一個位置
29     }
30     cout<<"The Num(new):";out(iVec);
31     return 0;
32 }
 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 using namespace std;
 5 
 6 int out(vector<int> &iVec)
 7 {
 8     for(int i=0;i<iVec.size();i++)
 9         cout<<iVec[i]<<ends;
10     cout<<endl;
11     return 0;
12 }
13 
14 int main()
15 {
16     vector<int> iVec;
17     vector<int>::iterator it;
18     int i;
19     for( i=0;i<10;i++)
20         iVec.push_back(i);
21 
22     cout<<"The Num(old):";out(iVec);
23     for(it=iVec.begin();it!=iVec.end();)
24     {
25         if(*it % 3 ==0)
26             it=iVec.erase(it);    //刪除元素,返回值指向已刪除元素的下一個位置    
27         else
28             ++it;    //指向下一個位置
29     }
30     cout<<"The Num(new):";out(iVec);
31     return 0;
32 }
container.erase(remove_if(container.begin(), container.end(), pred), container.end());?

文章鏈接: http://m.qzkangyuan.com/21655.html

文章標(biāo)題:std::remove

文章版權(quán):夢飛科技所發(fā)布的內(nèi)容,部分為原創(chuàng)文章,轉(zhuǎn)載請注明來源,網(wǎng)絡(luò)轉(zhuǎn)載文章如有侵權(quán)請聯(lián)系我們!

聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個人或組織,在未征得本站同意時,禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。

給TA打賞
共{{data.count}}人
人已打賞
建站教程

【C++】代碼實現(xiàn):運用 std::list 的 remove_if() 函數(shù)剔除數(shù)組中超出上下限的數(shù)據(jù)

2023-6-29 12:55:50

建站教程

C++設(shè)計模式:過濾器模式

2023-6-29 13:22:07

0 條回復(fù) A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個人中心
購物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索
主站蜘蛛池模板: 佛学| 阜新| 金川县| 巍山| 邹平县| 平塘县| 曲阳县| 江陵县| 醴陵市| 虞城县| 汪清县| 苗栗市| 清丰县| 保山市| 类乌齐县| 饶平县| 刚察县| 荥阳市| 宕昌县| 凌云县| 南皮县| 滁州市| 定结县| 尚义县| 基隆市| 平谷区| 保靖县| 商南县| 二手房| 晋州市| 三门县| 舞阳县| 汉源县| 罗城| 富川| 郧西县| 三门县| 永德县| 上思县| 遂昌县| 白朗县|